using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FlyFishMissile : MonoBehaviour
{
    public int face;
    public float damage;
    private Rigidbody2D myRigidbody;
    EnemyAttack enemyattack;
    public float damageratio;
    public int RepelTimes;
    public float RepelDistance, StiffTime;
    private PolygonCollider2D collider2D;
    private GameObject attackobject;

    Transform playertransform, transform;
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        collider2D = GetComponent<PolygonCollider2D>();
        attackobject = GameObject.FindWithTag("Player");
        //enemyattack= attackobject.GetComponent<EnemyAttack> ();
        //face = enemyattack.face;
        playertransform = attackobject.GetComponent<Transform>();
        transform = GetComponent<Transform>();
        damage*=EnemyData.damageratio;
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Player"))
        {

            other.GetComponent<PlayerBasic>().TakeDamage(damage, face, RepelTimes, RepelDistance, StiffTime);
            //Destroy(gameObject);
        }
        else if (other.gameObject.CompareTag("Shield"))
        {

            other.GetComponent<shield>().TakeDamage(damage);
            //Destroy(gameObject);
        }
        else if (other.gameObject.CompareTag("Creation"))
        {

            other.GetComponent<Creation>().TakeDamage(damage);
            //Destroy(gameObject);
        }
        else if (other.gameObject.CompareTag("Ground"))
        {
            Destroy(gameObject);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (playertransform.position.x < transform.position.x) face = -1;
        else face = 1;
    }
}
